#' ---
#' author: "```matthew.pietryka@gmail.com```"
#' date: "2019-12-17"
#' output:
#'  html_document:
#'    warning: false
#'    toc: true
#'    code_folding: hide
#' ---


#' **PURPOSE:**
#' This script creates plots to display the relationship between time and text similarity (Figure 4B). The relationship is estimated separately based on legislative partisan congruence"




# GET STARTED ---------------

#  load packages
library(tidyverse)


#  load data and plotting preferences
source("SC-Plots-Load-the-Data.R")
source("SC-Plots-Preferences.R")


# MAKE PLOT ---------------


party_time <- df_new  %>%
  mutate(party_same_lab = recode(party_same,`1` = "Same party",  `0` = "Mixed",
                                 `-1` = "Opposing parties") %>%
           fct_reorder(party_same))  %>%
  ggplot(aes(x = time_diff/365, y = ratio)) +
  facet_wrap(~party_same_lab) +
  geom_hline(yintercept = 0, size = 0.8) +
  geom_smooth(color = "grey30", size = 1.1, method = "loess") +
  theme_sc(axis_title_size = 14, base_size = 12, axis_title_just = "c") +
  theme(legend.position = "none") +
  xlab("Years between ratification") +
  ylab("Proportion borrowed") +
  theme(axis.text = element_text(size = rel(.9)))




graphics.off()
windows(6.5, 3)
party_time


# SAVE ---------------

graphics.off()
windows(6.5, 3)
party_time


ggsave("Plots/party_time.png")




